#include "header.h"

int main()
{
    int clientfd = socket(AF_INET , SOCK_STREAM , 0);
    ERROR_CHECK(clientfd , -1 , "socket");

    struct sockaddr_in serveraddr;
    memset(&serveraddr , 0 , sizeof(serveraddr));
    serveraddr.sin_family = AF_INET;
    serveraddr.sin_port = htons(9090);
    serveraddr.sin_addr.s_addr = inet_addr("127.0.0.1");

    int ret = connect(clientfd , (const struct sockaddr *)&serveraddr , 
                      sizeof(serveraddr));
    ERROR_CHECK(ret , -1 , "connect");

    printf("客户端连接成功！\n");

    // 指定用户态接收缓冲区
    char buff[1024] = {0};
    // 当第三个参数对数组使用 sizeof 运算符时
    // 表示最大可以接收数组的空间的数据量
    ret = recv(clientfd , buff , sizeof(clientfd) , 0);
    printf("服务端：%s \n接收了 %d 字节数据\n", buff , ret);

    const char * msg = "Hello , Server !";
    ret = send(clientfd , msg , strlen(msg) , 0);
    printf("客户端发送了 %d 字节数据\n" , ret);

    while(1);

    return 0;
}
